package com.cloud.pole.msg.biz;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.mapper.SmsTemplateMapper;
import com.cloud.pole.msg.model.entity.SmsTemplate;
import com.cloud.pole.msg.model.entity.SmsTemplateAdmin;

import tk.mybatis.mapper.entity.Example;

@Service
@Transactional(rollbackFor = Exception.class)
public class SmsTemplateBiz extends BaseBiz<SmsTemplateMapper, SmsTemplate>{
	
	@Autowired
	SmsTemplateMapper smsTemplateMapper;
	
	@Override
    @CacheClear(pre="sms-template{1.templateKey}")
    public void insertSelective(SmsTemplate entity) {
        super.insertSelective(entity);
    }
	
    @Override
    @CacheClear(pre="sms-template{1.templateKey}")
    public void updateSelectiveById(SmsTemplate entity) {
        super.updateSelectiveById(entity);
    }

    @Cache(key="sms-template{1}")
	public SmsTemplate selectByTemplateKey(String templateKey) {
        Example example = new Example(SmsTemplate.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("templateKey", templateKey);
        List<SmsTemplate> list = mapper.selectByExample(example);
        if(list== null || list.size()==0) {
        	return null;
        }
		return list.get(0);
	}

	public List<SmsTemplateAdmin> selectPageSmsTemplateAdminList(Map<String, Object> map) {
		return smsTemplateMapper.selectPageSmsTemplateAdminList(map);
	}

	public List<SmsTemplate> selectAllList(Map<String, Object> map) {
		return smsTemplateMapper.selectAllList(map);
	}
	
}
